package org.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.neuedu.entity.MedicalRecordDisease;
import org.neuedu.mapper.MedicalRecordDiseaseMapper;
import org.neuedu.service.MedicalRecordDiseaseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzw
 * @since 2024-11-17
 */
@Service
public class MedicalRecordDiseaseServiceImpl extends ServiceImpl<MedicalRecordDiseaseMapper, MedicalRecordDisease> implements MedicalRecordDiseaseService {
    @Override
    public List<Integer> getDiseaseIdsByMedicalId(Integer medicalRecordId) {
        List<Integer> result = new ArrayList<>();
        QueryWrapper<MedicalRecordDisease> wrapper = new QueryWrapper<>();
        wrapper.select("disease_id")
                .eq("medical_record_id", medicalRecordId);
        this.list(wrapper).forEach(entry -> {
            result.add(entry.getDiseaseId());
        });
        return result;
    }

    @Override
    public boolean delByDedicalId(Integer medicalRecordId) {
        UpdateWrapper<MedicalRecordDisease> wrapper = new UpdateWrapper<>();
        wrapper.eq("medical_record_id", medicalRecordId);
        return this.remove(wrapper);
    }
}
